load("//toolchain:toolchain.bzl", "protoc")

toolchain_type(
    name = "protoc",
    visibility = ["//visibility:public"],
)

toolchain(
    name = "standard",
    toolchain = ":compiled",
    toolchain_type = "//toolchain:protoc",
)

toolchain(
    name = "prebuilt",
    toolchain = ":precompiled",
    toolchain_type = "//toolchain:protoc",
)

protoc(
    name = "compiled",
    tool = "@com_google_protobuf//:protoc",
)

protoc(
    name = "precompiled",
    tool = ":protoc.exe",
)

genrule(
    name = "protoc_exe",
    srcs = select({
        "@bazel_tools//src/conditions:darwin": [
            "@prebuilt_protoc_osx//:protoc",
        ],
        "@bazel_tools//src/conditions:windows": [
            "@prebuilt_protoc_windows//:protoc",
        ],
        "//conditions:default": [
            "@prebuilt_protoc_linux//:protoc",
        ],
    }),
    outs = ["protoc.exe"],
    cmd = "cp $< $@",
    executable = True,
    visibility = ["//visibility:public"],
)

filegroup(
    name = "all_files",
    testonly = True,
    srcs = [
        "BUILD.bazel",
        "toolchain.bzl",
    ],
    visibility = ["//:__pkg__"],
)
